<?php
namespace Admin\Controller;

use Think\Controller;

class CustpController extends Controller
{

    public function custpInfo()
    {sess();
        $cust = M('Custp');
        $map = _search($dbname = "Custp");
        $map['zt']='y';
        $count = $cust->where($map)->count();
        $Page = getpage($count, 3); // 实例化分页类 传入总记录数
        $show = $Page->show(); // 分页显示输出
        $list = $cust->where($map)
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->select();
        $this->assign('list', $list);
        $this->assign('page', $show);
        updateTime();
        $this->display();
    }

    public function outxls()
    {sess();
        $model = M('Custp');
        $map = _search($dbname = "Custp");
        $map['zt']='y';
        $list = $model->where($map)->field('id,fenlei,title,xcrq,xingming,phone,qq,type,uname,addtime,updatetime')->select();
        $headArr = array(
            'ID',
            '进展',
            '公司名称',
            '下次联系',
            '联系人',
            '手机号码',
            'QQ',
            '客户来源',
            '更新人',
            '添加时间',
            '更新时间'
        );
        $filename = '客户信息';
        xlsout($filename, $headArr, $list);
        updateTime();
    }

    public function edit()
    {sess();
        $model = M('Custp');
        $Rs = $model->getById(I('get.id'));
        $this->assign('Rs', $Rs);
        if (IS_POST) {
            if (edit("Custp")) {
                $this->success('修改成功', U('Custp/custpInfo'));
            } else {
                $this->error('修改失败');
            }
        }
        updateTime();
        $this->display();
    }

    public function del()
    {sess();
        $model = M('Custp');
        $modeld = M('Cust');
        $map['id']=I('get.id');
        $data = $model->where($map)->field('id',true)->select();
        $model->startTrans();
        // 进行相关的业务逻辑操作
        $add = $modeld->addAll($data);
        $custp['zt']='n';
        $save = $model->where($map)->save($custp);
        if ($add && $save) {
            $model->commit();
            $this->success('挑入成功',U('Custp/custpInfo'));
        } else {
            $model->rollback();
            $this->error('挑入失败');
        }
        updateTime();
    }

}